{% extends "bet_base.html" %}
{% block extra_styles %}
<link rel="stylesheet" type="text/css" href="{{ MEDIA_URL }}styles/style2.css" />
{%endblock%}
{% block content %}

<div id="maincontent">
 <h1> Welcome home {{ profile.user }} </h1>
 <div class="intro">
 <p>This is your <b>bank page</b>. Shown below is your current balance and any bets you have made. You can buy and sell bets on <a href="/board"><b> the board</b></a>.</p>
 <p> Bets are added each week and the odds keep changing daily so check back often. When a bet you have made expires, you will be notified by email. </p>
<div class="button">
<input TYPE="BUTTON" VALUE="{%if total == 0%}Place your first bet!{%else%}Place a bet!{%endif%}" ONCLICK="window.location.href='/board'">
</div>
<br>

</div> 
<div class="bank">
<h2>Your Bankroll: ${{bankroll}}</h2>
</div>

{%if daily %}
<div class = "bets daily">
 <h2> Daily Bet </h2>
 <form action="board" method="post">
 {% csrf_token %}
<table>
<thead>
<th>Bet Description</th>
<th>Price</th>
<th> Expires </th>
<th>Buy</th>
<th>Sell</th>
</thead>
<tbody>
<tr>
<td> {{daily.bet.description }} </td>
<td> ${{daily.bet.price }} </td>
<td>
{{daily.bet.expired}}

</td>
<td> <input type="radio" onmousedown="this.__chk = this.checked" onclick="if (this.__chk) this.checked = false" name="bet{{daily.bet.id}}" id="daily" value="buy" />
<td> <input type="radio" onmousedown="this.__chk = this.checked" onclick="if (this.__chk) this.checked = false" name="bet{{daily.bet.id}}" id="daily" value="sell" />

</tr>
</tbody>
</table>
<br>
<div class="buttondark">
<input type="submit" value="Place Daily Bet!" />
</div>
</form>
</div>
{%endif%}

<div class = "bets">
 <h2> Your Bets </h2>
 {% if current == 0 %}
<h3>No current bets.</h3>
{%else%}
<form action="home" method="post">
 {% csrf_token %}
 <table>
  <thead>
 <tr>
 <th> Bet Description </th>
 <th> Price </th>
 <th> Expires </th>
 <th> Order </th>
 <th>Action</th>
 </tr>
 </thead>
 <tbody>
 {% for bet in bets %}
 {% if bet.bet.active and not bet.premature %}
 <tr>
 <td>{{bet.bet.description}}</td>
 <td>${{bet.bet.price}}</td>
 <td>
 {% if bet.bet.expired%}
{{bet.bet.expired.date}} at {{bet.bet.expired.time}}
 {%else%}
{{bet.bet.expired}}
{%endif%}
</td>
 <td>{%if bet.buy %}Bought{%else%}Sold{%endif%} at ${{bet.price}}</td>
 <td>{%if bet.buy %}Sell <input type="radio" onmousedown="this.__chk = this.checked" onclick="if (this.__chk) this.checked = false" name="bet{{bet.bet.id}}" id="{{bet.bet.id}}" value="sell" />{%else%} Buy <input type="radio" onmousedown="this.__chk = this.checked" onclick="if (this.__chk) this.checked = false" name="bet{{bet.bet.id}}" id="{{bet.bet.id}}" value="buy" />{%endif%} </td>
 </tr>
 {% endif %}
 {% endfor %}
 </tbody>
 </table>
 <div class="buttondark">
<input type="submit" value="Place Order!" />
</div>
</form>
{% endif %}
</div>

<div class = "bets">
<h2> Past Bets </h2>
{% if current == total %}
<h3>No past bets.</h3>
{%else%}
 <table>
 <thead>
 <tr>
 <th> Bet Description </th>
 <th> Final Price </th>
  <th> Order </th>
  <th> Occurred </th>
  <th> Return </th>
 </tr>
 </thead>
 <tbody>
 {% for bet in bets %}
 {% if not bet.bet.active or bet.premature %}
 <tr>
 {% if not bet.premature %}
 <td>{{bet.bet.description}}</td>
 <td>${{bet.bet.price}}</td>
  <td>{%if bet.buy %}Bought{%else%}Sold{%endif%} at ${{bet.price}}</td>
  <td>{%if bet.bet.outcome_set%}{%if bet.bet.win %}Yes{%else%}No{%endif%} on {{bet.bet.expired}}{%else%}Awaiting Decision. Expired on {{bet.bet.expired}}{%endif%}</td>
  <td class="nowrap">{%if bet.bet.outcome_set%}{% if not bet.return_sign %}-{%endif%}${{bet.bet_return}}{%else%}---{%endif%} </td>
 {% else %}
 <td>{{bet.bet.description}}</td>
 <td>${{bet.bet.price}}</td>
  <td>{%if bet.buy %}Bought{%else%}Sold{%endif%} at ${{bet.price}} then {% if bet.pre_buy %}Bought{%else%}Sold{%endif%} early at ${{bet.pre_price}}</td>
  <td>{%if bet.bet.outcome_set%}{%if bet.bet.win %}Yes{%else%}No{%endif%} on {{bet.bet.expired}}{%else%}{%if bet.bet.active %}Expires on {{bet.bet.expired.date}} at {{bet.bet.expired.time}}{%else%}Awaiting Decision. Expired on {{bet.bet.expired}}{%endif%}{%endif%} </td>
  <td class="nowrap">{% if not bet.return_sign %}-{%endif%}${{bet.bet_return}} </td>
  {%endif%}
 </tr>
 {% endif %}
 {% endfor %}
 </tbody>
 </table>
{%endif%}
</div>
</div>
{% endblock %}